// USB接口
interface USB {
    void openDevice();
    void closeDevice();
}
// 鼠标类，实现USB接口
class Mouse implements USB {
    @Override
    public void openDevice() {
        System.out.println("打开鼠标");
    }
    @Override
    public void closeDevice() {
        System.out.println("关闭鼠标");
    }
    public void click(){
        System.out.println("鼠标点击");
    }
}
// 键盘类，实现USB接口
class KeyBoard implements USB {
    @Override
    public void openDevice() {
        System.out.println("打开键盘");
    }
    @Override
    public void closeDevice() {
        System.out.println("关闭键盘");
    }
    public void inPut(){
        System.out.println("键盘输入");
    }
}
// 笔记本类：使用USB设备
class Computer {
    public void powerOn(){
        System.out.println("打开笔记本电脑");
    }
    public void powerOff(){
        System.out.println("关闭笔记本电脑");
    }
    public void useDevice(USB usb){
        usb.openDevice();
        if(usb instanceof Mouse){
            Mouse mouse = (Mouse)usb;
            mouse.click();
        }else if(usb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard)usb;
            keyBoard.inPut();
        }
        usb.closeDevice();
    }
}
public class Test_2 {
    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.powerOn();
        // 使用鼠标设备
        computer.useDevice(new Mouse());
        // 使用键盘设备
        computer.useDevice(new KeyBoard());
        computer.powerOff();
    }
}
//public class TestUSB {
//    public static void main(String[] args) {
//        USB usb = new USB();
//    }
//}
//// Error:USB是抽象的; 无法实例化
//public interface USB {
//    // Error: 此处不允许使用修饰符private
//    private void openDevice();
//    void closeDevice();
//}
//public interface USB {
//    void openDevice();
//    // 编译失败：因为接口中的方式默认为抽象方法
//// Error: 接口抽象方法不能带有主体
//    void closeDevice(){
//        System.out.println("关闭USB设备");
//    }
//}
//public interface USB {
//    void openDevice(); // 默认是public的
//    void closeDevice(); // 默认是public的
//}
//public class Mouse implements USB {
//    @Override
//    void openDevice() {
//        System.out.println("打开鼠标");
//    }
//}
//// 编译报错，重写USB中openDevice方法时，不能使用默认修饰符
//// 正在尝试分配更低的访问权限; 以前为public
//public interface USB {
//    double brand = 3.0; // 默认被：final public static修饰
//    void openDevice();
//    void closeDevice();
//}
//public class TestUSB {
//    public static void main(String[] args) {
//        System.out.println(USB.brand); // 可以直接通过接口名访问，说明是静态的
//// 编译报错：Error:(12, 12) java: 无法为最终变量brand分配值
//        USB.brand = 2.0; // 说明brand具有final属性
//    }
//}
//public interface USB {
//    // 编译失败
//    public USB(){
//    }
//    {} // 编译失败
//    void openDevice();
//    void closeDevice();
//}
class Animal {
    protected String name;
    public Animal(String name) {
        this.name = name;
    }
}
interface IFlying {
    void fly();
}
interface IRunning {
    void run();
}
interface ISwimming {
    void swim();
}
class Cat extends Animal implements IRunning {
    public Cat(String name) {
        super(name);
    }
    @Override
    public void run() {
        System.out.println(this.name + "正在用四条腿跑");
    }
}
class Fish extends Animal implements ISwimming {
    public Fish(String name) {
        super(name);
    }
    @Override
    public void swim() {
        System.out.println(this.name + "正在用尾巴游泳");
    }
}
class Frog extends Animal implements IRunning, ISwimming {
    public Frog(String name) {
        super(name);
    }
    @Override
    public void run() {
        System.out.println(this.name + "正在往前跳");
    }
    @Override
    public void swim() {
        System.out.println(this.name + "正在蹬腿游泳");
    }
}
class Duck extends Animal implements IRunning, ISwimming, IFlying {
    public Duck(String name) {
        super(name);
    }
    
    @Override
    public void fly() {
        System.out.println(this.name + "正在用翅膀飞");
    }
    @Override
    public void swim() {
        System.out.println(this.name + "正在漂在水上");
    }
    @Override
    public void run() {
        System.out.println(this.name + "正在用两条腿跑");
    }
}
//interface IRunning {
//    void run();
//}
//interface ISwimming {
//    void swim();
//}
//// 两栖的动物, 既能跑, 也能游
//interface IAmphibious extends IRunning, ISwimming {
//}
//class Frog implements IAmphibious {
//...
//}